<template>
	<view>
		<u-radio-group
		    v-model="selectValue"
		    @change="changeHandle"
		  >
		    <u-radio
		      :customStyle="{marginLeft: '8px'}"
		      v-for="(item, index) in options"
		      :key="index"
		      :label="item.dictLabel"
		      :name="item.dictValue"
		    >
		    </u-radio>
		</u-radio-group>
	</view>
</template>

<script>
export default {
	data() {
        return {
			options: [],
			selectValue: null
        }
	},
	props: {
		value: [String, Number],
		dictType: {
		    type: String,
		    default: ""
		},
		placeholder: {
		    type: String,
		    default: ""
		}	
	},
	computed: {
	    nativeValue() {
	      return this.value;
	    }
	},
	watch: {
	    //value改变
	    nativeValue() {
			if (this.selectValue === this.nativeValue) return;
			this.selectValue = this.nativeValue;
	    }
	},
	created() {
	    this.selectValue = this.nativeValue;
	    this.initData();
	},
	mounted() {
	},
	methods: {
	    async initData() {
			await this.$u.api.dict.getDicts(this.dictType).then((res) => {
				const { data } = res;
				this.options = data;
			});
	    },
	    changeHandle(val) {
			this.$emit('input', val);
			this.$emit('change', val);
	    }
	}
};
</script>

<style scoped>

</style>